﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using TamTreSoSinh.DBContext;

namespace TamTreSoSinh
{
    public partial class SiteMaster : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadMenu();
        }

        private void LoadMenu()
        {
            LoadServiceCategory();
            LoadShoppingCategory();
        }

        private void LoadShoppingCategory()
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            List<ShoppingCategory> listShoppingCategory = dbContext.ShoppingCategories.Where(obj => obj.IsVisible).OrderBy(obj => obj.Priority).ToList();

            rptMenuShopping.DataSource = listShoppingCategory;
            rptMenuShopping.DataBind();
        }

        private void LoadServiceCategory()
        {
            DBTamTreEntities dbContext = new DBTamTreEntities();
            List<ServiceCategory> listServiceCategory = dbContext.ServiceCategories.Where(obj => obj.IsVisible).OrderBy(obj => obj.Priority).ToList();

            rptMenuOurService.DataSource = listServiceCategory;
            rptMenuOurService.DataBind();
        }

        protected void rptMenuOurService_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink hpl = (HyperLink)e.Item.FindControl("hplMenuItem");
            ServiceCategory ourService = (ServiceCategory)e.Item.DataItem;
            hpl.Text = ourService.Title;
            hpl.NavigateUrl = @"~/ServicePage.aspx#AnchorService" + ourService.Id;
        }

        protected void rptMenuShopping_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            HyperLink hpl = (HyperLink)e.Item.FindControl("hplMenuItem");
            ShoppingCategory shoppingCategory = (ShoppingCategory)e.Item.DataItem;
            hpl.Text = shoppingCategory.Title;
            hpl.NavigateUrl = @"~/ShoppingCategoryPage.aspx#AnchorShopping" + shoppingCategory.Id;
        }
    }
}
